import pika

credentials = pika.PlainCredentials("guest","guest")
connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1',credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='TEST02')

def callback(ch, method, properties, body):
    print("消费者接受到了任务: %r" % body)

channel.basic_consume(queue='TEST02', on_message_callback=callback, auto_ack=True)
channel.start_consuming()